///////////////////////////////////////////////////////////////////////////////////////////////////
//
//  Copyright 2007 humbroll - WOC.  All rights reserved.
//
///////////////////////////////////////////////////////////////////////////////////////////////////
var M_BASEURL = "http://api.springnote.com/pages[detailURL]";

function queryEngine(){
	this.m_baseURL = M_BASEURL;
}
queryEngine.prototype.makeSearchQuery = function(p_keyWord){
	var m_url = this.m_baseURL;
	m_url = m_url.replace('[detailURL]',".xml;search?q=" + p_keyWord);
	return m_url;
}
queryEngine.prototype.makeGetPageQuery = function(p_page_id){
	var m_url = this.m_baseURL;
	m_url = m_url.replace('[detailURL]',"/" + p_page_id + ".xml");
	return m_url;
}
queryEngine.prototype.makeAddPageQuery = function(){
	var m_url = this.m_baseURL;
	m_url = m_url.replace('[detailURL]',".xml");
	return m_url;
}
queryEngine.prototype.makeAddXMLPageQuery = function(p_title,p_content){
	var m_content_xml = "<?xml version='1.0' encoding='UTF-8'?>" 
						+ "<page>"
						+ "<source> [source] </source>"
						+ "<title> [title] </title>"
						+ "</page>";
	m_content_xml = m_content_xml.replace('[title]',p_title);
	p_content = this.htmlGenerator(p_content);
	m_content_xml = m_content_xml.replace('[source]',p_content);
	return m_content_xml;
}
queryEngine.prototype.htmlGenerator = function(p_string){
	p_string = p_string.replace(/\r\n/g,"&lt;br/&gt;");
	return p_string	
}
//deprecated---------------------------------------------------------
queryEngine.prototype.getIDbyKeyWord = function(p_keyWord){
	var pages = M_PAGES.getElementsByTagName("page");
	var m_name = "";
	for(var i = 1 ; i <  pages.length ; i++){
		m_name = pages[i].childNodes[1].firstChild.nodeValue;
		if(m_name == p_keyWord){
			return pages[i].childNodes[0].firstChild.nodeValue;
		}
	}
}
//-------------------------------------------------------------------